package com.mingmen.supplier.util;

import com.alibaba.fastjson.JSON;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MyStringUtils {

    public static String returnStringBuffer(List<String> mynewId) {
        StringBuilder sb = new StringBuilder();
        String resultString = "";
        boolean flag = false;
        for (String str : mynewId) {
            if (flag) {
                sb.append(",");
            } else {
                flag = true;
            }
            sb.append(str);
        }
        resultString = sb.toString();
        return resultString;
    }

    public static <T> String beanToString(T value) {
        Class<?> clazz = value.getClass();
        if (clazz == int.class || clazz == Integer.class) {
            return value + "";
        } else if (clazz == String.class) {
            return (String) value;
        } else if (clazz == long.class || clazz == Long.class) {
            return value + "";
        } else {
            return JSON.toJSONString(value);
        }
    }

    public static boolean isSpecialChar(String str) {
        String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]|\n|\r|\t";

        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }
}
